// subcontract/Find/exhibitionDetails/exhibitionDetails.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    aliyunServrBaseURL: getApp().config.aliyunServrBaseURL,//阿里云公共地址
    exhibitionID: '',//展会详情
    exhibitionInfo: {},//展会信息
    current: 1,//选中的第几个轮播
    userinfo: getApp().userinfo,//用户信息
    userList: [],//参展列表
    userShow: false,
    page: 1,//页码
    pagingState: false,//分页状态
    ExhibitionList: [],//商圈列表
    type: 0,
  },
  navigateTo(event) {
    console.log(event);
    let { url, item, type, details } = event.currentTarget.dataset
    console.log(details);
    let TTUL = this
    wx.navigateTo({
      url,
      success: function (res) {
        if (details != 'Details') {
          res.eventChannel.emit('exhibitionInfo', { type, ...item })
        }
      }
    })
  },
  /**找展会 */
  async getExhibitionList(keywords) {
    let object = {
      page_no: this.data.page,
      likeness: 1,
      id: this.data.exhibitionID
    }
    if (!this.data.pagingState) {
      const { code, data } = await getApp().api.getExhibitionList(object)
      if (code == 1) {
        this.setData({
          isenabled: false,
          ExhibitionList: this.data.ExhibitionList.concat(data.list).map(item => {
            item.end_time = getApp().timestampToDate(item.end_time * 1000, 'Y-m-d')
            return item
          })
        })
        if (data.more != 1) {
          this.setData({
            pagingState: true
          })
          return
        }
        this.setData({
          page: (this.data.page * 1) + 1
        })
      }
    }
  },
  openUseList(event) {
    let { type } = event.currentTarget.dataset
    this.setData({
      type,
      userShow: true
    })
  },
  /**复制下载来链接 */
  setClipboardDat() {
    let { type, exhibitionInfo } = this.data
    wx.setClipboardData({
      data: type == 0 ? exhibitionInfo.excel_file.type_0 : exhibitionInfo.excel_file.type_1,
      success: function () {
        wx.showToast({
          title: '复制成功,请到浏览器下载',
          icon: 'none',
          duration: 2000
        });
      },
      fail: function () {
        wx.showToast({
          title: '复制失败',
          icon: 'none',
          duration: 2000
        });
      }
    });
  },
  /**关闭弹框 */
  onClose(event) {
    console.log(event);
    this.setData({
      userShow: false
    })
  },
  /**选择的第几个 */
  async swiperChange(event) {
    console.log(event);
    let { current } = event.detail
    this.setData({
      current: current + 1,
    })
  },
  openMap: function () {
    let { exhibitionInfo } = this.data
    wx.openLocation({
      latitude: exhibitionInfo.latitude * 1, // 纬度，范围为-90~90，负数表示南纬
      longitude: exhibitionInfo.longitude * 1, // 经度，范围为-180~180，负数表示西经
      name: exhibitionInfo.site, // 位置名
      address: exhibitionInfo.address, // 地址的详细说明
      success: function (res) {
        // 成功打开地图后的回调
        console.log('打开地图成功');
      },
      fail: function (res) {
        // 打开地图失败的回调
        console.log('打开地图失败', res);
      }
    });
  },
  /**展会详情 */
  async getExhibitionInfo(id) {
    let object = {
      id
    }
    const { code, data } = await getApp().api.getExhibitionInfo(object)
    if (code == 1) {
      data.time = getApp().timestampToDate(data.start_time * 1000, 'Y.m.d') + '-' + getApp().timestampToDate(data.end_time * 1000, 'm.d')
      data.content = data.content.replace(/\<img/gi, '<img style="max-width:100%;height:auto" '),
        this.setData({
          exhibitionInfo: data
        })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      exhibitionID: options.id
    })
    this.getExhibitionInfo(options.id)
    this.getExhibitionList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})